package top.infopub.mgr.ic.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.flow.cnst.FlowTemplateEnum;
import top.infopub.mgr.flow.service.WsFlowProcessService;
import top.infopub.mgr.ic.dao.StopBuildDao;
import top.infopub.mgr.ic.domain.StopBuildDomain;
import top.infopub.mgr.ic.service.StopBuildService;
import top.infopub.mgr.ic.vo.StopBuildVo;
import top.infopub.model.ic.StopBuild;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


@Service
public class StopBuildServiceImpl extends GenericServiceImpl<StopBuild, String> implements StopBuildService {

    @Autowired
    private StopBuildDao stopBuildDao;

    @Autowired
    private WsFlowProcessService wsFlowProcess;

    @Override
    public GenericDao<StopBuild, String> getDao() {
        return stopBuildDao;
    }

    @Override
    public Page<StopBuildDomain> selectByDomainWhere(Page<StopBuildDomain> page,
                                                     StopBuildVo stopBuildVo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<StopBuildDomain>)stopBuildDao.selectByDomainWhere(stopBuildVo);
    }

    @Override
    public Page<StopBuildDomain> selectMyCheckByDomainWhere(Page<StopBuildDomain> page,
                                                            StopBuildVo stopBuildVo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<StopBuildDomain>)stopBuildDao.selectMyCheckByDomainWhere(stopBuildVo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveStopBuild(StopBuild stopBuild) {

        stopBuildDao.insertById(stopBuild);

        // 注意 这里根据不同的业务分支判断条件 获得不同enum
        FlowTemplateEnum flowTemplateEnum = FlowTemplateEnum.IC_STOP_BUILD;
        // 处理工作流数据
        wsFlowProcess.launch(flowTemplateEnum, stopBuild.getId(), stopBuild.getProcessId(), null);

    }

    @Override
    public StopBuildVo queryById(String id) {
        return stopBuildDao.queryById(id);
    }

}